package com.kgc.novel.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author jcq
 * @since 2023-05-17
 */
@Getter
@Setter
@NoArgsConstructor
@Api(tags = "订单类")
@TableName("book_order")
public class BookOrder implements Serializable {

 private static final long serialVersionUID = 1L;

    /**
     * 订单主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 用户id
     */
    @ApiParam("用户id")
    @TableField("user_id")
    private String userId;

    /**
     * 订单编号
     */
    @ApiParam("订单编号")
    @TableField("order_no")
    private String orderNo;

    /**
     * 会员折扣id
     */
    @ApiParam("会员折扣id")
    @TableField("discount_id")
    private String discountId;

    /**
     * 订单金额
     */
    @ApiParam("订单金额")
    @TableField("order_amount")
    private BigDecimal orderAmount;

    /**
     * 支付订单号
     */
    @ApiParam("支付订单号")
    @TableField("transaction_id")
    private String transactionId;

    /**
     * 支付方式（1支付宝  2微信  3抖音）
     */
    @ApiParam("支付方式")
    @TableField("order_way")
    private Byte orderWay;

    /**
     * 下单时间
     */
    @ApiParam("下单时间")
    @TableField("order_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime orderTime;

    /**
     * 支付时间
     */
    @ApiParam("支付时间")
    @TableField("pay_time")
    private LocalDateTime payTime;

    /**
     * 退款时间
     */
    @ApiParam("退款时间")
    @TableField("refund_time")
    private LocalDateTime refundTime;

    /**
     * 退款原因
     */
    @ApiParam("退款原因")
    @TableField("refund_reason")
    private String refundReason;

    /**
     * 退款金额
     */
    @ApiParam("退款金额")
    @TableField("refund_amount")
    private BigDecimal refundAmount;

    /**
     * 订单描述
     */
    @ApiParam("订单描述")
    @TableField("order_description")
    private String orderDescription;

    /**
     * 订单状态（-2:已关闭，-1:已退款，0:待付款，1:待评价，2:已评价）
     */
    @ApiParam("订单状态")
    @TableField("order_status")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Byte orderStatus;

    /**
     * 是否删除
     */
    @ApiParam("是否删除")
    @TableField("deleted")
    @TableLogic
    private Boolean deleted;

    /**
     * 修改时间
     */
    @ApiParam("修改时间")
    @TableField(value = "update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    public BookOrder(BookOrder bookOrder) {
        if (Objects.nonNull(bookOrder)) {
            this.id = bookOrder.id;
            this.userId = bookOrder.userId;
            this.orderNo = bookOrder.orderNo;
            this.discountId = bookOrder.discountId;
            this.orderAmount = bookOrder.orderAmount;
            this.transactionId = bookOrder.transactionId;
            this.orderWay = bookOrder.orderWay;
            this.orderTime = bookOrder.orderTime;
            this.payTime = bookOrder.payTime;
            this.refundTime = bookOrder.refundTime;
            this.refundReason = bookOrder.refundReason;
            this.refundAmount = bookOrder.refundAmount;
            this.orderDescription = bookOrder.orderDescription;
            this.orderStatus = bookOrder.orderStatus;
            this.deleted = bookOrder.deleted;
            this.updateTime = bookOrder.updateTime;
        }
    }
}
